#!/bin/bash

echo "========================================"
echo "   AIDE OpenAI API 配置向导"
echo "========================================"
echo ""

echo "请按照以下步骤配置OpenAI API:"
echo ""
echo "1. 访问 https://platform.openai.com/api-keys"
echo "2. 创建新的API密钥"
echo "3. 复制生成的密钥"
echo ""

read -p "请输入您的OpenAI API密钥: " api_key

if [ -z "$api_key" ]; then
    echo "❌ 错误: API密钥不能为空"
    exit 1
fi

echo ""
echo "正在创建 .env 文件..."

cat > .env << EOF
# OpenAI API配置
OPENAI_API_KEY=$api_key
OPENAI_BASE_URL=https://api.openai.com/v1
OPENAI_MODEL=gpt-3.5-turbo

# 数据库配置
DB_HOST=localhost
DB_PORT=5432
DB_NAME=aide
DB_USER=postgres
DB_PASSWORD=unidt@123

# 服务器配置
PORT=5000
NODE_ENV=development
EOF

echo "✅ .env 文件创建成功！"
echo ""
echo "现在您可以:"
echo "1. 运行 'npm run test-openai' 测试OpenAI集成"
echo "2. 运行 'npm run dev' 启动后端服务"
echo ""
echo "配置完成！"
